/*
 * BluePadScreen.java
 *
 * Created on June 5, 2007, 9:37 PM
 */

package com.bloomingstars.bluepad;

import com.bloomingstars.bluepad.comm.CommandCode;
import com.bloomingstars.bluepad.comm.DA2Comm;
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.game.GameCanvas;

/**
 *
 * @author toni
 */
public class BluePadScreen extends GameCanvas
{
    private final DA2Comm comm;

    public BluePadScreen(DA2Comm comm)
    {
        super(false);
        this.comm = comm;
    }
    
    public void paint(Graphics g)
    {
        g.setColor(0,10,155);
        g.fillRect(0,0,getWidth(),getHeight());
    }
    
    protected void keyPressed(int keycode)
    {
        int gameAction = getGameAction(keycode);

        if (gameAction == Canvas.LEFT)
        {
            comm.send(CommandCode.MOVE_WEST);
        }
        else if (gameAction == Canvas.RIGHT)
        {
            comm.send(CommandCode.MOVE_EAST);
        }
        else if(gameAction == Canvas.UP)
        {
            comm.send(CommandCode.MOVE_NORTH);
        }
        else if(gameAction == Canvas.DOWN)
        {
            comm.send(CommandCode.MOVE_SOUTH);
        }
    }
    
    protected void keyReleased(int keycode)
    {
        int gameAction = getGameAction(keycode);
        
        if (gameAction == Canvas.LEFT)
        {
            comm.send(CommandCode.RELEASE_WEST);
        }
        else if (gameAction == Canvas.RIGHT)
        {
            comm.send(CommandCode.RELEASE_EAST);
        }
        else if(gameAction == Canvas.UP)
        {
            comm.send(CommandCode.RELEASE_NORTH);
        }
        else if(gameAction == Canvas.DOWN)
        {
            comm.send(CommandCode.RELEASE_SOUTH);
        }
    } 
}
